package com.lzs.kunei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzs.entity.Puton;
import com.lzs.kunei.mapper.PutonMapper;
import com.lzs.kunei.service.PutonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzs.util.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 上架 服务实现类
 * </p>
 *
 * @author wpy
 * @since 2020-11-24
 */
@Service
public class PutonServiceImpl extends ServiceImpl<PutonMapper, Puton> implements PutonService {
    @Autowired
    private PutonMapper putonMapper;
    @Override
    public Page<Puton> selectPutonPage(Integer current, Integer size, Puton puton,String[] warehouseid) {
        Page<Puton> putonPage=new Page<>(current,size);
        Long commodityid = puton.getCommodityid();
        String commodityname = puton.getCommodityname();
        String locatorcode = puton.getLocatorcode();
        String locatorname = puton.getLocatorname();
        String state = puton.getState();
        QueryWrapper<Puton> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("warehouseid",warehouseid);
        if (commodityid!=null&&commodityid.toString()!=""){
            queryWrapper.like("commodityid",commodityid);
        }
        if (StringUtils.isNotEmpty(commodityname)){
            queryWrapper.like("commodityname",commodityname);
        }
        if (StringUtils.isNotEmpty(locatorcode)){
            queryWrapper.like("locatorcode",locatorcode);
        }
        if (StringUtils.isNotEmpty(locatorname)){
            queryWrapper.like("locatorname",locatorname);
        }
        if (StringUtils.isNotEmpty(state)){
            queryWrapper.like("state",state);
        }
        putonMapper.selectPage(putonPage,queryWrapper);
        return putonPage;
    }

    @Override
    public R updateAudit(String state, List<Long> list) {
        int i=-1;
        if (list!=null&&list.size()>0){
             i = putonMapper.updateAudit(state, list);
        }
       if (i!=-1){
           return R.ok().message("操作成功");
       }else {
           return R.error().message("操作成功");
       }
    }


}
